package td3.model;

import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;

public class ContactFileTransferable implements Transferable {

	private List<File> files;

	protected static final DataFlavor contactsFileFlavor = DataFlavor.javaFileListFlavor;

	public ContactFileTransferable(List<File> files) {
		super();
		this.files = files;
	}

	public static DataFlavor getNodeFlavor() {
		return contactsFileFlavor;
	}

	@Override
	public Object getTransferData(DataFlavor flavor)
			throws UnsupportedFlavorException, IOException {
		if (flavor == contactsFileFlavor && files.size() == 1)
			return files;
		return null;
	}

	@Override
	public DataFlavor[] getTransferDataFlavors() {
		DataFlavor[] result = { contactsFileFlavor };
		return result;
	}

	@Override
	public boolean isDataFlavorSupported(DataFlavor flavor) {
		return Arrays.asList(getTransferDataFlavors()).contains(flavor);
	}

}
